/*
    XTU OJ: 1477
    by: fifth_light
*/

#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int bing[100010] = {0};
        int zhi[100010] = {0};
        int t;
        scanf("%d", &t);
        for (int j = 0; j < t; j++) {
            int type;
            scanf("%d", &type);
            bing[type]++;
        }
        scanf("%d", &t);
        for (int j = 0; j < t; j++) {
            int type;
            scanf("%d", &type);
            zhi[type]++;
        }
        int give_out = 0;
        int receive_in = 0;
        for (int i = 0; i < 100010; i++) {
            if (bing[i] == 0 && zhi[i] > 1) {
                receive_in++;
            }
            if (zhi[i] == 0 && bing[i] > 1) {
                give_out++;
            }
        }
        // printf("receive: %d, give: %d\n", receive_in, give_out);
        int result = give_out > receive_in ? receive_in : give_out;
        printf("%d\n", result);
    }
    return 0;
}
